﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace AFT2
{
    [Serializable]
    public class CallDataObject
    {
        public CallDataObject(string type, string phoneNumber, string name, string date, string duration)
        {
            Type = type;
            PhoneNumber = phoneNumber;
            Name = name;
            Date = date;
            Duration = duration;
        }
        public string Type { get; set; }
        public string PhoneNumber { get; set; }
        public string Name { get; set; }
        public string Date { get; set; }
        public string Duration { get; set; }
    }
    [Serializable]
    public class CallDataList
    {
        public CallDataList()
        {
            this.data = new List<CallDataObject>();

            SQLiteConnection myConnection = new SQLiteConnection();
            myConnection.ConnectionString = "Data Source=db\\phoneData.db";
            myConnection.Open();
            SQLiteCommand sqlcmd = new SQLiteCommand(myConnection);
            sqlcmd.CommandText = "select * from calllog;";
            SQLiteDataReader reader = sqlcmd.ExecuteReader();
            while (reader.Read())
            {
                this.data.Add(
                    new CallDataObject(
                        "" + reader["type"],
                        "" + reader["number"],
                        "" + reader["name"],
                        "" + reader["date"],
                        "" + reader["duration"])
                    );
            }

            reader.Close();
            myConnection.Close();
        }

        public List<CallDataObject> data;
    }
}
